#include "StdAfx.h"
#include "RectangleObj.h"


CRectangleObj::CRectangleObj(void):CShape()
{
	m_shapeStyle = SHAPE_RECTANGLE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_width=0.5;
	m_PortID=0;
	m_bDriveRect=false;
	m_bMaxRect=false;
	m_dblFillColorR =0;
	m_dblFillColorG =0;
	m_dblFillColorB =0;
	m_dblGradientFillColorR=0;
	m_dblGradientFillColorG=0;
	m_dblGradientFillColorB=0;
	m_IsChangePotColor=false;
	m_IsPotRect=false;
	m_IsBackGroundRect=false;
}

CRectangleObj::CRectangleObj( CEntityObj* pParentEnt ):CShape(pParentEnt)
{
	m_shapeStyle = SHAPE_RECTANGLE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_width=0.5;
	m_PortID=0;
	m_bDriveRect=false;
	m_bMaxRect=false;
	m_dblFillColorR =0;
	m_dblFillColorG =0;
	m_dblFillColorB =0;
	m_dblGradientFillColorR=0;
	m_dblGradientFillColorG=0;
	m_dblGradientFillColorB=0;
	m_IsChangePotColor=false;
	m_IsPotRect=false;
	m_IsBackGroundRect=false;
}

CRectangleObj::CRectangleObj( const CRectangleObj* pSrc ):CShape(pSrc)
{
	m_shapeStyle = pSrc->getShapeStyle();

	m_dblStartPosX = pSrc->GetStartPosX();	
	m_dblStartPosY = pSrc->GetStartPosY();	
	m_dblEndPosX = pSrc->GetEndPosX();	
	m_dblEndPosY = pSrc->GetEndPosY();	
	m_dblR=pSrc->GetColorR();
	m_dblG=pSrc->GetColorG();
	m_dblB=pSrc->GetColorB();
	m_width=pSrc->GetWidth();
	m_PortID=pSrc->GetPortID();
	m_bDriveRect=pSrc->GetDriveRect();
	m_bMaxRect=pSrc->GetMaxRect();
	m_dblFillColorR =pSrc->GetFillColorR();
	m_dblFillColorG =pSrc->GetFillColorG();
	m_dblFillColorB =pSrc->GetFillColorB();
	m_dblGradientFillColorR=pSrc->GetGradientFillColorR();
	m_dblGradientFillColorG=pSrc->GetGradientFillColorG();
	m_dblGradientFillColorB=pSrc->GetGradientFillColorB();
	m_IsChangePotColor=pSrc->GetIsChangePotColor();
	m_IsPotRect=pSrc->GetIsPotRect();
	m_IsBackGroundRect=pSrc->GetIsBackGroundRect();
}


CRectangleObj::~CRectangleObj(void)
{
}

void CRectangleObj::Serialize( CArchive & ar )
{
	if (GetIsSvgGroundShape()||GetIsSvgComponentShape())
	{
		if (ar.IsStoring())
		{
			ar << m_dblStartPosX;	
			ar << m_dblStartPosY;	
			ar << m_dblEndPosX;	
			ar << m_dblEndPosY;	
			ar<<m_dblR;
			ar<<m_dblG;
			ar<<m_dblB;
			ar<<m_width;
			ar<<m_PortID;
			ar<<m_bDriveRect;
			ar<<m_bMaxRect;
			ar<<m_dblFillColorR;
			ar<<m_dblFillColorG;
			ar<<m_dblFillColorB;
			ar<<m_dblGradientFillColorR;
			ar<<m_dblGradientFillColorG;
			ar<<m_dblGradientFillColorB;
			ar<<m_IsChangePotColor;
			ar<<m_IsPotRect;
			ar<<m_IsBackGroundRect;
		} 
		else
		{
			ar >> m_dblStartPosX;	
			ar >> m_dblStartPosY;	
			ar >> m_dblEndPosX;	
			ar >> m_dblEndPosY;	
			ar >>m_dblR;
			ar >>m_dblG;
			ar >>m_dblB;
			ar >>m_width;
			ar >>m_PortID;
			ar >>m_bDriveRect;
			ar >>m_bMaxRect;
			ar >>m_dblFillColorR;
			ar >>m_dblFillColorG;
			ar >>m_dblFillColorB;
			ar >>m_dblGradientFillColorR;
			ar >>m_dblGradientFillColorG;
			ar >>m_dblGradientFillColorB;
			ar >>m_IsChangePotColor;
			ar >>m_IsPotRect;
			ar >>m_IsBackGroundRect;
		}
	}
	CShape::Serialize(ar);
}
/////////
double CRectangleObj::GetStartPosX() const
{
	return m_dblStartPosX;
}
double CRectangleObj::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CRectangleObj::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CRectangleObj::GetEndPosY() const
{
	return m_dblEndPosY;
}
void CRectangleObj::SetStartPosX(double posX)
{
	m_dblStartPosX = posX;
}

void CRectangleObj::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CRectangleObj::SetEndPosX(double posX)
{
	m_dblEndPosX = posX;
}

void CRectangleObj::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

CDisplayObj * CRectangleObj::CreateDisplayObj( long lLayerId )
{
	CRectangleDisplayObj *pRectDis = new CRectangleDisplayObj(this);
	pRectDis->SetLayerId(lLayerId);
	return pRectDis;
}


void CRectangleObj::CopyDisplayObj( long lSourceLayerId, long lDestLayerId )
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CRectangleObj::DeleteDisplayObj( long lLayerId )
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}



void CRectangleObj::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
}

void CRectangleObj::SetColor( double colorR, double colorG, double colorB )
{
	m_dblR = colorR;
	m_dblG = colorG;
	m_dblB = colorB;
}

void CRectangleObj::SetFillColor( double colorR, double colorG, double colorB )
{
	m_dblFillColorR = colorR;
	m_dblFillColorG = colorG;
	m_dblFillColorB = colorB;
}

void CRectangleObj::SetGradientFillColor( double colorR, double colorG, double colorB )
{
	m_dblGradientFillColorR = colorR;
	m_dblGradientFillColorG = colorG;
	m_dblGradientFillColorB = colorB;
}

CObj * CRectangleObj::Clone() const
{
	return new CRectangleObj(this);
}
